package com.ship.dispatch.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.common.core.domain.R;
import com.ship.common.core.exception.BusException;
import com.ship.common.core.utils.BeanCopyUtils;
import com.ship.common.core.utils.StringUtils;
import com.ship.common.core.utils.bean.BeanUtils;
import com.ship.common.core.web.domain.BaseResultCode;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.dispatch.bean.ConShipping;
import com.ship.dispatch.bean.performance.*;
import com.ship.dispatch.bean.performance.vo.*;
import com.ship.dispatch.mapper.performance.PerformanceConMapper;
import com.ship.dispatch.mapper.performance.PerformanceDisMapper;
import com.ship.dispatch.mapper.performance.PerformanceListMapper;
import com.ship.dispatch.service.PerformanceListService;
import com.ship.system.api.RemoteFileService;
import com.ship.system.api.domain.SysFile;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class PerformanceListServiceImpl extends BaseServiceImpl<PerformanceListMapper, PerformanceList> implements PerformanceListService {

    @Autowired
    PerformanceListMapper performanceListMapper;
    @Autowired
    PerformanceConMapper performanceConMapper;
    @Autowired
    PerformanceDisMapper performanceDisMapper;

    @Autowired
    private RemoteFileService remoteFileService;

    @Value("${file_server.host}")
    private String fileServerHost;

    @Override
    public JsonResult<PageInfo<PerformanceList>> getListInfo(PerformanceListVo performanceListVo) {
        List<PerformanceList> result = new ArrayList<>();
        PageHelper.startPage(performanceListVo.getPageNum(),performanceListVo.getPageSize());
        List<PerformanceList> imoList = performanceConMapper.queryPerformanceList(performanceListVo);
        PageInfo<PerformanceList> pageInfo = new PageInfo<>(imoList);
        if (CollectionUtil.isNotEmpty(imoList)){
            imoList.forEach(item -> {
                PerformanceList performanceList = performanceConMapper.queryPerformance(item.getId());
                PerformanceDis performanceDis = performanceDisMapper.getinfoById(performanceList.getImo());
                String fromBUrl = performanceDisMapper.getFromB(performanceList.getImo());
                if (item != null && item.getNameOfVessel() != null) {
                    if (performanceList.getContractType().equals("1")) {
                        performanceList.setContractType("租入长期船");
                    }
                    if (performanceList.getContractType().equals("2") ) {
                        performanceList.setContractType("租入短期船");
                    }
                    if (performanceList.getContractType().equals("3")) {
                        performanceList.setContractType("船舶租出");
                    }
                    if (performanceList.getContractType().equals("4")) {
                        performanceList.setContractType("内部转租");
                    }
                    if (performanceList.getTradeBody().equals("1")) {
                        performanceList.setTradeBody("国贸");
                    }
                    if (performanceList.getTradeBody().equals("2")) {
                        performanceList.setTradeBody("新贸");
                    }

                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getMmsi())){
                        performanceList.setMmsi(performanceDis.getMmsi());
                    }
                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getShipStatus())){
                        performanceList.setShipStatus(performanceDis.getShipStatus());
                    }
                    performanceList.setFromB(fromBUrl);
                }
                result.add(performanceList);
            });
        }
//        result = result.stream().distinct().collect(Collectors.toList());
//        int totalItems = result.size();
//        Map<String,Object> performanceList1 = new HashMap<>();
//        performanceList1.put("result",result);
//        performanceList1.put("pageNum",performanceListVo.getPageNum());
//        performanceList1.put("pageSize",performanceListVo.getPageSize());
//        performanceList1.put("total",totalItems);
        PageInfo<PerformanceList> pageInfo1 = new PageInfo<>();
        BeanUtils.copyProperties(pageInfo,pageInfo1);
        pageInfo1.setList(result);
        return JsonResult.success(pageInfo1);
    }

    @Override
    public JsonResult getInfo(String id) {
        PerformanceCon performanceCon = performanceConMapper.getinfoById(id);
        PerformanceDis performanceDis = performanceDisMapper.getinfoById(performanceCon.getImo());
        String FromB = performanceDisMapper.getFromB(performanceCon.getImo());
        if (performanceCon.getContractType() == 1){
            performanceCon.setContractTypeValue("国贸");
        }else if (performanceCon.getContractType() == 2){
            performanceCon.setContractTypeValue("新贸");
        }
        Map<String,String> performanceList = new HashMap<>();
        performanceList.put("nameOfVessel",performanceCon.getShipName());//船舶名称
        performanceCon.setFromBUrl(FromB);
        if (null != performanceDis){
            performanceCon.setMmsi(performanceDis.getMmsi());
            performanceCon.setShipStatus(performanceDis.getShipStatus());
            performanceList.put("shipStatus",performanceDis.getShipStatus());//航行状态

            performanceList.put("mmsi",performanceDis.getMmsi());//MMSI
        }
        performanceList.put("imo",performanceCon.getImo());//imo
        if (performanceCon.getContractType()==1){
            performanceList.put("tradeBody","国贸");
        }
        if (performanceCon.getContractType()==2) {
            performanceList.put("tradeBody","新贸");
        }
        performanceList.put("fromB",FromB);//FromB
        return JsonResult.success(performanceCon);
    }

    @Override
    public JsonResult getTenancyInfo(Integer pageNum,Integer pageSize,String imo) {
        PageHelper.startPage(pageNum,pageSize);
        List<ConShipping> conShippingList = performanceConMapper.getTenancyInfo(imo);
        PageInfo<ConShipping> pageInfo = new PageInfo<>(conShippingList);
        List<PerformConShipping> performConShippings = new ArrayList<>();
        for (ConShipping conShipping : conShippingList) {
            PerformConShipping tenancyInfo = new PerformConShipping();
            tenancyInfo.setId(conShipping.getId());
            tenancyInfo.setShipName(conShipping.getShipName());
            tenancyInfo.setImo(conShipping.getImo());
            if (conShipping.getContractType()==1){
                tenancyInfo.setContractType("租入长期船");
            }
            if (conShipping.getContractType()==2){
                tenancyInfo.setContractType("租入短期船");
            }
            if (conShipping.getContractType()==3){
                tenancyInfo.setContractType("船舶租出");
            }
            if (conShipping.getContractType()==4){
                tenancyInfo.setContractType("内部转租");
            }
            tenancyInfo.setDeliveryDate(conShipping.getDeliveryDate());
            tenancyInfo.setShipowner(conShipping.getShipowner());
            tenancyInfo.setTenant(conShipping.getTenant());
            tenancyInfo.setLeaseTermStr(conShipping.getLeaseTermStr());
            tenancyInfo.setRedeliveryDate(conShipping.getRedeliveryDate());
            performConShippings.add(tenancyInfo);
        }
        PageInfo<PerformConShipping> pageInfo1 = new PageInfo<>();
        BeanUtils.copyProperties(pageInfo,pageInfo1);
        pageInfo1.setList(performConShippings);
        return JsonResult.success(pageInfo1);
    }

    @Override
    public JsonResult getHistoryInfo(PerformanceHis performanceHis) {
        PageHelper.startPage(performanceHis.getPageNum(),performanceHis.getPageSize());
        List<PerformanceHisList> performanceHisLists = performanceListMapper.getHisByImo(performanceHis.getImo());
//        if (!performanceHis.getVoyageNo().isEmpty()) {
//            List<PerformanceHisList> filteredList = new ArrayList<>();
//            for (PerformanceHisList hisList : performanceHisLists) {
//                if (performanceHis.getVoyageNo().equals(hisList.getVoyageNumber())) {
//                    filteredList.add(hisList);
//                }
//            }
//            performanceHisLists = filteredList;
//        }
        PageInfo<PerformanceHisList> pageInfo = new PageInfo<>(performanceHisLists);
        return JsonResult.success(pageInfo);
    }

    @Override
    public JsonResult getReportInfo(PerformanceHis performanceHis) {
        PageHelper.startPage(performanceHis.getPageNum(),performanceHis.getPageSize());
        List<PerformanceRepList> performanceHisLists = performanceListMapper.getRepByImo(performanceHis.getImo());
        if (!performanceHis.getVoyageNo().isEmpty()) {
            List<PerformanceRepList> filteredList = new ArrayList<>();
            for (PerformanceRepList hisList : performanceHisLists) {
                if (performanceHis.getVoyageNo().equals(hisList.getVoyageNumber())) {
                    filteredList.add(hisList);
                }
            }
            performanceHisLists = filteredList;
        }
        PageInfo<PerformanceRepList> pageInfo = new PageInfo<>(performanceHisLists);
        return JsonResult.success(pageInfo);
    }

    @Override
    public JsonResult getOverhaulInfo(Integer pageNum,Integer pageSize,String imo) {
        PageHelper.startPage(pageNum,pageSize);
        List<PerformanceOveList> performanceOveLists = performanceConMapper.getOverhaulInfo(imo);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
//        for (PerformanceOveList oveList : performanceOveLists) {
//            Date inspectionTime = oveList.getInspectionTime();
//            if (inspectionTime != null) {
////                LocalDate localDate = inspectionTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
////                String formattedDate = localDate.format(formatter);
//                String formattedDate = DateUtil.format(inspectionTime, DatePattern.NORM_DATE_FORMATTER);
//                oveList.setInspectionTimeStr(formattedDate);
//            }
//        }
        PageInfo<PerformanceOveList> pageInfo = new PageInfo<>(performanceOveLists);
        return JsonResult.success(pageInfo);
    }

    @Override
    public String export(PerformanceExp performanceExp) {
        String imo = performanceExp.getImo();
        String shipName = performanceListMapper.getNameByImo(imo);
        String voyageNumber = performanceExp.getVoyageNumber();
        String filePath = "";
        Date currentTime = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String dateString = dateFormat.format(currentTime);

        if (performanceExp.getType()==1){
            filePath = shipName+"船舶租期"+dateString+".xlsx";
            List<ConShipping> conShippingList = performanceConMapper.getTenancyInfo(imo);
            List<PerformConShipping> performConShippings = new ArrayList<>();
            for (ConShipping conShipping : conShippingList) {
                PerformConShipping tenancyInfo = new PerformConShipping();
                tenancyInfo.setId(conShipping.getId());
                tenancyInfo.setShipName(conShipping.getShipName());
                tenancyInfo.setImo(conShipping.getImo());
                if (conShipping.getContractType()==1){
                    tenancyInfo.setContractType("租入长期船");
                }
                if (conShipping.getContractType()==2){
                    tenancyInfo.setContractType("租入短期船");
                }
                if (conShipping.getContractType()==3){
                    tenancyInfo.setContractType("船舶租出");
                }
                if (conShipping.getContractType()==4){
                    tenancyInfo.setContractType("内部转租");
                }
                tenancyInfo.setDeliveryDate(conShipping.getDeliveryDate());
                tenancyInfo.setShipowner(conShipping.getShipowner());
                tenancyInfo.setTenant(conShipping.getTenant());
                tenancyInfo.setLeaseTermStr(conShipping.getLeaseTermStr());
                tenancyInfo.setRedeliveryDate(conShipping.getRedeliveryDate());

                performConShippings.add(tenancyInfo);
            }
            try (Workbook workbook = new XSSFWorkbook()) {
                Sheet sheet = workbook.createSheet("船舶租期");

                // 创建表头
                Row headerRow = sheet.createRow(0);
                String[] headers = {"船舶名称", "IMO", "合同类型", "交船日期", "船东", "租家", "租期", "还船日期"};
                for (int i = 0; i < headers.length; i++) {
                    Cell cell = headerRow.createCell(i);
                    cell.setCellValue(headers[i]);
                }

                // 写入数据
                int rowNum = 1;
                for (PerformConShipping performConShipping : performConShippings) {
                    Row row = sheet.createRow(rowNum++);

                    row.createCell(0).setCellValue(performConShipping.getShipName());
                    row.createCell(1).setCellValue(performConShipping.getImo());
                    row.createCell(2).setCellValue(performConShipping.getContractType());
                    row.createCell(3).setCellValue(performConShipping.getDeliveryDate());
                    row.createCell(4).setCellValue(performConShipping.getShipowner());
                    row.createCell(5).setCellValue(performConShipping.getTenant());
                    row.createCell(6).setCellValue(performConShipping.getLeaseTermStr());
                    row.createCell(7).setCellValue(performConShipping.getRedeliveryDate());
                }

                // 保存文件
                try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
                    workbook.write(fileOut);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (performanceExp.getType()==2){
            filePath = shipName+"历史航次"+dateString+".xlsx";
            List<PerformanceHisList> performanceHisLists = performanceListMapper.getHisByImo(imo);
            if (StringUtils.isNotEmpty(voyageNumber)) {
                List<PerformanceHisList> filteredList = new ArrayList<>();
                for (PerformanceHisList hisList : performanceHisLists) {
                    if (voyageNumber.equals(hisList.getVoyageNumber())) {
                        filteredList.add(hisList);
                    }
                }
                performanceHisLists = filteredList;
            }
            try (Workbook workbook = new XSSFWorkbook()) {
                Sheet sheet = workbook.createSheet("历史航次");

                // 创建表头
                Row headerRow = sheet.createRow(0);
                String[] headers = {"航次号","方案执行状态", "装载港", "卸载港口"};
                for (int i = 0; i < headers.length; i++) {
                    Cell cell = headerRow.createCell(i);
                    cell.setCellValue(headers[i]);
                }
                // 写入数据
                int rowNum = 1;
                for (PerformanceHisList performanceHisList : performanceHisLists) {
                    Row row = sheet.createRow(rowNum++);

                    row.createCell(0).setCellValue(performanceHisList.getVoyageNumber());

                    String status = null;
                    if (StringUtils.isNotEmpty(performanceHisList.getExecuteStatus())){
                        if ("0".equals(performanceHisList.getExecuteStatus())){
                            status = "未下发";
                        }else if ("1".equals(performanceHisList.getExecuteStatus())){
                            status = "已下发";
                        }else if ("2".equals(performanceHisList.getExecuteStatus())){
                            status = "已排布";
                        }else if ("3".equals(performanceHisList.getExecuteStatus())){
                            status = "已完成";
                        }else if ("5".equals(performanceHisList.getExecuteStatus())){
                            status = "已终止";
                        }
                        performanceHisList.setExecuteStatus(status);
                    }
                    row.createCell(1).setCellValue(performanceHisList.getExecuteStatus());
                    row.createCell(2).setCellValue(performanceHisList.getShipReportDate());
                    row.createCell(3).setCellValue(performanceHisList.getExpectedUnloadingPort());
                }

                // 保存文件
                try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
                    workbook.write(fileOut);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (performanceExp.getType()==3){
            filePath = shipName+"午报"+dateString+".xlsx";
            List<PerformanceRepList> performanceHisLists = performanceListMapper.getRepByImo(imo);
            if (StringUtils.isNotEmpty(voyageNumber)) {
                List<PerformanceRepList> filteredList = new ArrayList<>();
                for (PerformanceRepList hisList : performanceHisLists) {
                    if (voyageNumber.equals(hisList.getVoyageNumber())) {
                        filteredList.add(hisList);
                    }
                }
                performanceHisLists = filteredList;
            }
            try (Workbook workbook = new XSSFWorkbook()) {
                Sheet sheet = workbook.createSheet("午报");

                // 创建表头
                Row headerRow = sheet.createRow(0);
                String[] headers = {"Voyage number", "Date", "LAT", "LONG"};
                for (int i = 0; i < headers.length; i++) {
                    Cell cell = headerRow.createCell(i);
                    cell.setCellValue(headers[i]);
                }
                // 写入数据
                int rowNum = 1;
                for (PerformanceRepList performanceRepList : performanceHisLists) {
                    Row row = sheet.createRow(rowNum++);

                    row.createCell(0).setCellValue(performanceRepList.getVoyageNumber());
                    row.createCell(1).setCellValue(performanceRepList.getShipReportDate());
                    row.createCell(2).setCellValue(performanceRepList.getPositionLat());
                    row.createCell(3).setCellValue(performanceRepList.getPositionLong());
                }

                // 保存文件
                try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
                    workbook.write(fileOut);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (performanceExp.getType()==4){
            filePath = shipName+"船舶检修记录"+dateString+".xlsx";
            List<PerformanceOveList> performanceOveLists = performanceConMapper.getOverhaulInfo(imo);
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");

//            for (PerformanceOveList oveList : performanceOveLists) {
//                Date inspectionTime = oveList.getInspectionTime();
//                if (inspectionTime != null) {
//                    LocalDate localDate = inspectionTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//                    String formattedDate = localDate.format(formatter);
//                    oveList.setInspectionTimeStr(formattedDate);
//                }
//            }

            try (Workbook workbook = new XSSFWorkbook()) {
                Sheet sheet = workbook.createSheet("船舶检修记录");

                // 创建表头
                Row headerRow = sheet.createRow(0);
                String[] headers = {"检修时间", "检修内容", "备注"};
                for (int i = 0; i < headers.length; i++) {
                    Cell cell = headerRow.createCell(i);
                    cell.setCellValue(headers[i]);
                }
                // 写入数据
                int rowNum = 1;
                for (PerformanceOveList performanceOveList : performanceOveLists) {
                    Row row = sheet.createRow(rowNum++);

                    row.createCell(0).setCellValue(performanceOveList.getInspectionTimeStr());
                    row.createCell(1).setCellValue(performanceOveList.getInspectionContent());
                    row.createCell(2).setCellValue(performanceOveList.getRemarks());
                }

                // 保存文件
                try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
                    workbook.write(fileOut);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        if (performanceExp.getType()==5){

        }
        //文件地址

        File file = new File(filePath);
        //声明参数集合
//        HashMap<String, Object> paramMap = new HashMap<>();
//        //文件
//        paramMap.put("file", file);
//        //输出
//        paramMap.put("output","json");
//        //自定义路径
//        paramMap.put("path","image");
//        //场景
//        paramMap.put("scene","image");
//
//        paramMap.put("filename",filePath);

//        String result= HttpUtil.post("http://106.12.241.246:8083/group1/upload", paramMap);
//        String result= HttpUtil.post(fileServerHost+"/group1/upload", paramMap);
        MultipartFile multipartFile = getMultipartFile(file);
        R<SysFile> result = remoteFileService.upload(multipartFile);
        if (file.exists()) {
            file.delete();
        }
//        Gson gson = new Gson();
//        JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
//        // 获取"url"字段的值
//        String url = jsonObject.get("url").getAsString();
        if(result.getCode() != R.SUCCESS){
            throw new BusException("文件服务器连接失败", BaseResultCode.GENERAL_ERROR);
        }
        String url = result.getData().getHttpUrl();

        String CsoldPart = "http://10.75.34.224:9300/statics";
        String ZsoldPart = "http://10.75.33.149:9300/statics";
        String CsPart = "https://lngshippingcs.cgp.cnooc/api/file/statics";
        String ZsPart = "https://lngshipping.cgp.cnooc/api/file/statics";

        String newUrl = "";
        if (url.contains("http://10.75.34.224:9300/statics")) {
            newUrl = url.replace(CsoldPart, CsPart);
        }else if (url.contains("http://10.75.33.149:9300/statics")){
            newUrl = url.replace(ZsoldPart, ZsPart);
        }else {
            newUrl = url;
        }

        return newUrl;
    }

    @Override
    public List<String> queryShipNameList() {
        List<String> shipNameList = performanceConMapper.queryShipNameList();
        return shipNameList.stream().distinct().collect(Collectors.toList());
    }

    @Override
    public List<PerformanceList> SchemeDetailPageExport(List<Long> ids) {
        List<PerformanceList> result = new ArrayList<>();
        PerformanceListVo performanceListVo = new PerformanceListVo();
        if (CollectionUtil.isNotEmpty(ids)){
            performanceListVo.setIds(ids);
        }
        List<PerformanceList> imoList = performanceConMapper.queryPerformanceList(performanceListVo);
        PageInfo<PerformanceList> pageInfo = new PageInfo<>(imoList);
        if (CollectionUtil.isNotEmpty(imoList)){
            imoList.forEach(item -> {
                PerformanceList performanceList = performanceConMapper.queryPerformance(item.getId());
                PerformanceDis performanceDis = performanceDisMapper.getinfoById(performanceList.getImo());
                String fromBUrl = performanceDisMapper.getFromB(performanceList.getImo());
                if (item != null && item.getNameOfVessel() != null) {
                    if (performanceList.getContractType().equals("1")) {
                        performanceList.setContractType("租入长期船");
                    }
                    if (performanceList.getContractType().equals("2") ) {
                        performanceList.setContractType("租入短期船");
                    }
                    if (performanceList.getContractType().equals("3")) {
                        performanceList.setContractType("船舶租出");
                    }
                    if (performanceList.getContractType().equals("4")) {
                        performanceList.setContractType("内部转租");
                    }
                    if (performanceList.getTradeBody().equals("1")) {
                        performanceList.setTradeBody("国贸");
                    }
                    if (performanceList.getTradeBody().equals("2")) {
                        performanceList.setTradeBody("新贸");
                    }

                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getMmsi())){
                        performanceList.setMmsi(performanceDis.getMmsi());
                    }
                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getShipStatus())){
                        performanceList.setShipStatus(performanceDis.getShipStatus());
                    }
                    performanceList.setFromB(fromBUrl);
                }
                result.add(performanceList);
            });
        }
//        List<PerformanceList> imoList = performanceConMapper.SchemeDetailPageExport(ids);
//        if (CollectionUtil.isNotEmpty(imoList)){
//            imoList.forEach(item -> {
//                PerformanceDis performanceDis = performanceDisMapper.getinfoById(item.getImo());
//                String fromBUrl = performanceDisMapper.getFromB(item.getImo());
//                if (item != null && item.getNameOfVessel() != null) {
//                    if (item.getContractType().equals("1")) {
//                        item.setContractType("租入长期船");
//                    }
//                    if (item.getContractType().equals("2") ) {
//                        item.setContractType("租入短期船");
//                    }
//                    if (item.getContractType().equals("3")) {
//                        item.setContractType("船舶租出");
//                    }
//                    if (item.getContractType().equals("4")) {
//                        item.setContractType("内部转租");
//                    }
//                    if (item.getTradeBody().equals("1")) {
//                        item.setTradeBody("国贸");
//                    }
//                    if (item.getTradeBody().equals("2")) {
//                        item.setTradeBody("新贸");
//                    }
//
//                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getMmsi())){
//                        item.setMmsi(performanceDis.getMmsi());
//                    }
//                    if (null != performanceDis && StringUtils.isNotEmpty(performanceDis.getShipStatus())){
//                        item.setShipStatus(performanceDis.getShipStatus());
//                    }
//                    item.setFromB(fromBUrl);
//                }
//
//            });
//        }
        return result;
    }

    public static MultipartFile getMultipartFile(File file) {
        FileItem item = new DiskFileItemFactory().createItem("file"
                , MediaType.MULTIPART_FORM_DATA_VALUE
                , true
                , file.getName());
        try (InputStream input = new FileInputStream(file);
             OutputStream os = item.getOutputStream()) {
            // 流转移
            IOUtils.copy(input, os);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid file: " + e, e);
        }

        return new CommonsMultipartFile(item);
    }

    private boolean isEmptyList(List<?> list) {
        return list == null || list.isEmpty();
    }
}
